package com.own.business.message.center.controller.manage;

import com.own.aop.permission.PermissionModule;
import com.own.business.message.center.business.service.MessageCenterContentService;
import com.own.business.message.center.entity.dto.MessageCenterContentDto;
import com.own.business.message.center.entity.map.MessageCenterContentMapVo;
import com.own.business.message.center.entity.query.MessageCenterContentQuery;
import com.own.business.message.center.entity.vo.MessageCenterContentVo;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.PageModel;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationModuleAop;
import com.own.component.store.core.confirm.aop.ConfirmAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * ManageMessageCenterContentController
 *
 * @author chenxueli
 * @date 2023-11-13 14:39:27
 */
@Tag(name = "消息中心内容" + ConstantBeanSuffix.MANAGE_CLIENT + ConstantBeanSuffix.CONTROLLER)
@RestController
@PermissionModule("message-center-content")
@LogOperationModuleAop("消息中心内容" + ConstantBeanSuffix.MANAGE_CLIENT)
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ConstantApiPrefix.MANAGE_CLIENT + "message/center/content")
public class ManageMessageCenterContentController extends BaseController {

    @Resource
    private MessageCenterContentService messageCenterContentService;

    @Operation(summary = "查询所有信息")
    @PostMapping("/all")
    public ResultModel<List<MessageCenterContentVo>> all(
            @RequestBody MessageCenterContentQuery query
    ) {
        var list = messageCenterContentService.all(query);
        return R.success(list);
    }

    @Operation(summary = "分页查询信息")
    @PostMapping("/page")
    public ResultModel<PageModel<MessageCenterContentVo>> page(
            @RequestBody MessageCenterContentQuery query
    ) {
        var pageModel = messageCenterContentService.page(query);
        return R.success(pageModel);
    }

    @Operation(summary = "map查询信息")
    @PostMapping("/map")
    public ResultModel<List<MessageCenterContentMapVo>> map(
            @RequestBody MessageCenterContentQuery query
    ) {
        var list = messageCenterContentService.map(query);
        return R.success(list);
    }

    @Operation(summary = "添加信息")
    @PostMapping("/")
    public ResultModel<MessageCenterContentVo> add(
            @Validated @RequestBody MessageCenterContentDto dto
    ) {
        dto.check();
        var updateModel = messageCenterContentService.add(dto.toBo());
        return R.success(updateModel);
    }

    @Operation(summary = "修改信息")
    @PutMapping("/{messageCenterContentId}")
    public ResultModel<MessageCenterContentVo> update(
            @Parameter(description = "主键id", required = true) @PathVariable Long messageCenterContentId,
            @Validated @RequestBody MessageCenterContentDto dto
    ) {
        dto.check();
        var updateModel = messageCenterContentService.update(messageCenterContentId, dto.toBo());
        return R.success(updateModel);
    }

    @ConfirmAop(message = "确认删除该项目？（注意：删除之后无法找回数据，且该项目所有资料会被删除）")
    @Operation(summary = "删除信息")
    @DeleteMapping("/{messageCenterContentId}")
    public ResultModel<Boolean> delete(
            @Parameter(description = "主键id", required = true) @PathVariable Long messageCenterContentId
    ) {
        var updateModel = messageCenterContentService.delete(messageCenterContentId);
        return R.success(updateModel);
    }

    @Operation(summary = "根据id获取信息")
    @GetMapping("/{messageCenterContentId}")
    public ResultModel<MessageCenterContentVo> getById(
            @Parameter(description = "主键id", required = true) @PathVariable Long messageCenterContentId
    ) {
        var vo = messageCenterContentService.getById(messageCenterContentId);
        return R.success(vo);
    }

}
